package com.acoreful.acf2java.admin.config;

import javax.annotation.PostConstruct;

import org.apache.commons.lang3.SystemUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import com.acoreful.acf2java.commons.redis.RedisOps;
import com.google.common.collect.ImmutableMap;

import lombok.Getter;

@Component
@Getter
public class AdminConfig {
    private Logger logger=LoggerFactory.getLogger(AdminConfig.class);
    // 这些url都是绝对路径
    // 之所以配置此值, 是因为有些需要重定向的地方, 如果前端有nginx, 那么相对路径是会计算错误

    @Value("${app.url.index}")
    private String appUrlIndex; // 应用首页url
    
    @Value("${app.url.login}")
    private String appUrlLogin; // 应用登录页url
    @Autowired
    private StringRedisTemplate stringRedisTemplate;
    
    @Bean
    public RedisOps createRedisOps() {
    	RedisOps op=new RedisOps();
    	op.setStringRedisTemplate(stringRedisTemplate);
    	return op;
    }
    @PostConstruct
    public void setup() {
    	printSystemEnvProperties();
    }
    private void printSystemEnvProperties() {
		ImmutableMap.builder().put("操作系统", SystemUtils.OS_NAME).put("操作系统版本", SystemUtils.OS_VERSION)
				.put("操作系统架构", SystemUtils.OS_ARCH).put("文件编码", SystemUtils.FILE_ENCODING)
				.put("当前用户", SystemUtils.USER_NAME).put("当前用户目录", SystemUtils.USER_HOME)
				.put("当前用户时区", SystemUtils.USER_TIMEZONE).put("Java", SystemUtils.JAVA_RUNTIME_NAME)
				.put("Java供应商", SystemUtils.JAVA_VENDOR).put("Java版本", SystemUtils.JAVA_RUNTIME_VERSION)
				.put("Java虚拟机", SystemUtils.JAVA_VM_NAME).put("Java虚拟机供应商", SystemUtils.JAVA_VM_VENDOR)
				.put("Java虚拟机版本", SystemUtils.JAVA_VM_VERSION).build().forEach((k, v) -> logger.info("{} - {}", k, v));
	}
}